class Lough < ActiveRecord::Base
  include ConfigManager
  
  belongs_to :user
  has_many :articles
  
  has_many (:published_articles,
            :class_name => 'Article',
  			:conditions => {:published => true},
  			:order => 'published_at DESC')
  
  validates_presence_of :screen_name
  validates_uniqueness_of :screen_name
  
  serialize :settings, Hash
  
  # Description
  setting :lough_name,        :string, ''
  setting :about_owner,       :string, ''
  setting :copy_right,        :string, ''
  
  # Articles
  setting :article_per_page,  :integer, 10
  setting :recent_count,	  :integer, 8
  
  def initialize(*args)
    super
    
    begin
      self.settings ||= {}
    rescue
      self.settings = {}
    end
  end

  def request_pagination_articles(params)
  	published_articles.find_pagination_by_date(*params.values_at(:year, :month, :day, :page))
  end
  
  def request_recent_articles()
  	published_articles.find_recent_published(recent_count)
  end
  
  def request_article(params)
    Article.find_by_id(params[:id])
  end

end
